#ifndef SELECT_ATTRS_H
#define  SELECT_ATTRS_H

#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include "lexcal.h"

//=============================================
//Class: select_attrs
//       This class get the infomation of select 
//       attributions,and make it bitmap.
//Author:Junix <unix_jun@yahoo.com.cn> 
//=============================================

class select_attrs
{
public:
    select_attrs ()
    {
    }

    select_attrs (string select_file)
    {
        string sselect;
        ifstream sf (select_file.c_str ());
        if (getline (sf, sselect))
        {
            while (!sselect.empty ())
                _bitmap.push_back (atoi (cell (sselect, ' ').c_str ()));
            sort (_bitmap.begin (), _bitmap.end ());
	    _bitmap.erase( unique(_bitmap.begin(), _bitmap.end()) ,_bitmap.end());
        }
    }

    ~select_attrs ()
    {
        _bitmap.clear ();
    }

    bool selected (int test)
    {
        if (find (_bitmap.begin (), _bitmap.end (), test) != _bitmap.end ())
            return true;
        else
            return false;

    }

    vector<int>& bitmap()
    {
        return _bitmap;
    }


    int print ()
    {
	cout<<endl<<"====================================================="<<endl;
	cout<<"select attributions"<<endl<<endl;
        copy(_bitmap.begin(),_bitmap.end(),ostream_iterator<int>(cout," "));
        cout<<std::endl;
	cout<<"====================================================="<<endl;
    }

    friend ostream& operator << (ostream& os,const select_attrs& attr)
    {
        copy(attr._bitmap.begin(),attr._bitmap.end(),ostream_iterator<int>(os," "));
        os<<std::endl;
        return os;
    }
    //all select attr are stored in a vector.
    vector < int >  _bitmap;
};
#endif
